import request from '@/utils/request'

// 统一管理属性接口
const API = {
  C1: '/admin/product/getCategory1',
  C2: '/admin/product/getCategory2/',
  C3: '/admin/product/getCategory3/',
  ATTRINFO_URL: '/admin/product/attrInfoList/',
  ADDORUPDATEATTR_URL: 'admin/product/saveAttrInfo',
  DELETEATTR_URL: 'admin/product/deleteAttr/'
}

// 获取一级分类接口
export const getCategory1API = () => request.get(API.C1)

// 获取二级分类接口
export const getCategory2API = (c1Id) => request.get(API.C2 + c1Id)

// 获取三级分类接口
export const getCategory3API = (c2Id) => request.get(API.C3 + c2Id)

// 获取属性信息接口
export const getAttrInfoAPI = (c1Id, c2Id, c3Id) =>
  request.get(API.ATTRINFO_URL + `${c1Id}/${c2Id}/${c3Id}`)

// 添加或修改属性接口(使用同一个接口，根据传参是否含id判断为修改或添加)
export const addOrUpdateAttrAPI = (data) => request.post(API.ADDORUPDATEATTR_URL, data)

// 删除某一个已有属性接口
export const deleteAttrAPI = (attrId) => request.delete(API.DELETEATTR_URL + attrId)